#include<iostream>
#include<stack>
#include<unordered_map>
using namespace std;

class Solution {
public:
    bool isValid(string s) {
        stack<char> stk;
        unordered_map<char, char> map ={{')', '('}, {'}', '{'}, {']', '['}};
        for(char c : s) {
            if(c == '(' || c == '[' || c == '{') {
                stk.push(c);
            }else if(c == ')' || c == ']' || c == '}') {
                if(stk.empty() || stk.top() != map[c]) {
                    return false;
                }
                stk.pop();
            }
        }
        return stk.empty();
    }
};

int main()
{
    Solution sol;
    string s = "()"; 
    cout << sol.isValid(s) << endl;
    return 0;
}